//
//  B_MaterialOrderDetailVC.m
//  DreamOf
//
//  Created by 薛小刚 on 2018/9/20.
//  Copyright © 2018年 薛小刚. All rights reserved.
//

#import "B_MaterialOrderDetailVC.h"
#import "B_OrderHeaderView.h"
#import "B_OrderDetailTVC.h"
#import "B_OrderDetailLabelTVC.h"
#import "B_OrrderFooterView.h"
#import "B_TwoButtonRightFooterView.h"

@interface B_MaterialOrderDetailVC ()
@property (nonatomic, strong) BaseView * mainView;

@property (nonatomic, strong) B_TwoButtonRightFooterView * footerView;
@end

@implementation B_MaterialOrderDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"订单详情"];
    self.view = self.mainView;
    [self getData];
}

/*
 需要根据不同的状态 分别配套底部的按钮状态
 */
- (BaseView *)mainView {
    if (!_mainView) {
        WeakSelf(weSelf, self);
        _mainView = [[BaseView alloc] init];
        [_mainView addSubview:self.footerView];
        [self.footerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mainView.mas_left);
            make.right.equalTo(self.mainView.mas_right);
            make.bottom.equalTo(self.mainView.mas_bottom);
            make.height.equalTo(@(50));
        }];
        CGFloat bottom = SCREEN_HEIGHT > 800 ? (50 + 24) : 50;
        [_mainView setTableViewFrameWithTop:5 left:0 right:0 bottom:-bottom];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_OrderDetailTVC" bundle:nil] forCellReuseIdentifier:@"B_OrderDetailTVC"];
        [_mainView.tableView registerNib:[UINib nibWithNibName:@"B_OrderDetailLabelTVC" bundle:nil] forCellReuseIdentifier:@"B_OrderDetailLabelTVC"];
        _mainView.numberOfSectionsBlock = ^NSInteger(UITableView *tableView) {
            return 2;
        };
        _mainView.numberOfRowsBlock = ^NSInteger(UITableView *tableView, NSInteger section) {
            if (section == 0) {
                return 1;
            } else {
                return 0;
            }
        };
        
        _mainView.viewForHeaderBlock = ^UIView *(UITableView *tableView, NSInteger section) {
            if (section == 0) {
                B_OrderHeaderView * header = [B_OrderHeaderView initB_OrderHeaderView];
                header.B_orderNumber.text = [NSString stringWithFormat:@"订单号: %@", @"asdf"];
                header.B_orderStatus.text = @"待付款";
                header.B_userName.text = @"易小川";
                header.B_userPhone.text = @"18888888888";
                header.B_userAddress.text = @"山西省";
                header.B_merchantTitle.text = @"阿斯蒂芬";
                return header;
            } else {
                return nil;
            }
        };
        _mainView.viewForFooterBlock = ^UIView *(UITableView *tableView, NSInteger section) {
            if (section == 0) {
                B_OrrderFooterView * footer = [B_OrrderFooterView initB_OrrderFooterView];
                footer.B_titleLabel.text = [NSString stringWithFormat:@"共计%@件, 共¥%.2f", @"1", 100];
                return footer;
            } else {
                return nil;
            }
        };
        
        _mainView.cellForRowBlock = ^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
            if (indexPath.section == 0) {
                B_OrderDetailTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_OrderDetailTVC" forIndexPath:indexPath];
                cell.B_goodsImageView.backgroundColor = [UIColor redColor];
                cell.B_goodsTitle.text = @"猪肝";
                cell.B_goodsPrice.attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@", @"200"]];
                cell.B_goodsCount.text = [NSString stringWithFormat:@"x %@", @"1"];
                return cell;
            } else {
                B_OrderDetailLabelTVC * cell = [tableView dequeueReusableCellWithIdentifier:@"B_OrderDetailLabelTVC" forIndexPath:indexPath];
                cell.B_titleLabel.text = [NSString stringWithFormat:@"运单编号: %@", @"234234"];;
                return cell;
            }
        };
    }
    return _mainView;
}


- (B_TwoButtonRightFooterView *)footerView {
    
    if (!_footerView) {
        WeakSelf(weSelf, self);
        _footerView = [B_TwoButtonRightFooterView initB_TwoButtonRightFooterView];
        //待付款状态  显示两个按钮  取消订单  立即付款
//        if ([self.orderDetailModel.type isEqualToString:@"1"]) {
//            [_footerView.B_leftButton setTitle:@"取消订单" forState:UIControlStateNormal];
//            [_footerView.B_rightButton setTitle:@"立即付款" forState:UIControlStateNormal];
//            _footerView.B_twoButtonAction = ^(UIButton *btn) {
//                if ([btn.titleLabel.text isEqualToString:@"取消订单"]) {
//                    /// TODO:取消订单
//                } else {
//                    /// TODO:立即付款
//                }
//            };
//        } else if ([self.orderDetailModel.type isEqualToString:@"2"]) {
//            _footerView.B_leftButton.hidden = YES;
//            [_footerView.B_rightButton setTitle:@"确认收货" forState:UIControlStateNormal];
//            _footerView.B_twoButtonAction = ^(UIButton *btn) {
//                if ([btn.titleLabel.text isEqualToString:@"确认收货"]) {
//                    /// TODO:确认收货
//                } else {
//
//                }
//            };
//        } else if ([self.orderDetailModel.type isEqualToString:@"3"]) {
//            _footerView.B_leftButton.hidden = YES;
//            [_footerView.B_rightButton setTitle:@"再来一单" forState:UIControlStateNormal];
//            _footerView.B_twoButtonAction = ^(UIButton *btn) {
//                if ([btn.titleLabel.text isEqualToString:@"再来一单"]) {
//                    /// TODO:再来一单
//                } else {
//                }
//            };
//        }
//
//        //待收货状态  显示一个按钮  确认收货
//
//        //已完成状态 A  显示一个按钮  再来一单  B 没有状态
//
//        // 配型中状态  没有
        
        //待发货状态显示一个按钮  发货
    }
    return _footerView;
}


- (void) getData {
    WeakSelf(weSelf, self);
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
